From dcbe8e9583d3b618dc87431af250a29325175503 Mon Sep 17 00:00:00 2001 From: robertlipe Date: Mon, 15 Dec 2014 00:00:43 +0000 Subject: [PATCH] Ew. Internally force-match QStrings and C strings in GPX write version number to prevent leak. --- gpsbabel/gpx.cc | 9 ++++++++- gpsbabel/magproto.cc | 8 ++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/gpsbabel/gpx.cc b/gpsbabel/gpx.cc index 52f105050..5360134a0 100644 --- a/gpsbabel/gpx.cc +++ b/gpsbabel/gpx.cc @@ -1802,7 +1802,14 @@ gpx_write(void) if (gpx_version.isEmpty()) { gpx_wversion = (char*)"1.0"; } else { - gpx_wversion = xstrdup(gpx_version); + // FIXME: this is gross. The surrounding code is badly tortured by + // there being three concepts of "output version", each with a different + // data type (QString, int, char*). This section needs a rethink. For + // now, we stuff over the QString gpx_version into the global char * + // gpx_wversion without making a malloc'ed copy. + static char tmp[16]; + strncpy(tmp, CSTR(gpx_version), sizeof(tmp)); + gpx_wversion = tmp; } } diff --git a/gpsbabel/magproto.cc b/gpsbabel/magproto.cc index 2c9e11be5..5161e5adf 100644 --- a/gpsbabel/magproto.cc +++ b/gpsbabel/magproto.cc @@ -20,9 +20,6 @@ */ -#include -#include - #include "defs.h" #include "magellan.h" #include "gbser.h" @@ -33,6 +30,8 @@ #endif #include #include +#include +#include static int bitrate = 4800; static int wptcmtcnt; @@ -1067,7 +1066,8 @@ mag_rteparse(char* rtemsg) rte_name = "Route"; rte_name += QString::number(rtenum); } else { - rte_name = xstrndup(ca, ce - ca); + rte_name = ca; + rte_name.truncate(ce-ca); } n += ((ce - ca) + 1); -- 2.30.2